package com.liming.coupon.controller;

import com.liming.common.pojo.dto.coupon.AddCouponDTO;
import com.liming.common.pojo.dto.coupon.CouponPageQuery;
import com.liming.common.pojo.dto.coupon.UpdateCouponDTO;
import com.liming.common.pojo.vo.PageVO;
import com.liming.common.pojo.vo.coupon.openfeign.FeignCouponVO;
import com.liming.common.result.LMResult;
import com.liming.coupon.service.CouponMircoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author liming
 * @date 2025/1/18
 */
@Slf4j
@RestController
@AllArgsConstructor
@Tag(name = "优惠券后台接口-Service")
@RequestMapping("/service/coupon_admin")
public class CouponAdminMircoController {

    private final CouponMircoService couponMircoService;

    @Operation(summary = "分页")
    @GetMapping
    public LMResult<PageVO<FeignCouponVO>> page(CouponPageQuery query) {
        PageVO<FeignCouponVO> result = couponMircoService.pageCoupon(query);
        return LMResult.success(result);
    }

    @Operation(summary = "详情")
    @GetMapping("{id}")
    public LMResult<FeignCouponVO> get(@PathVariable Long id){
        FeignCouponVO vo = couponMircoService.getCouponById(id);
        return LMResult.success(vo);
    }

    @Schema(description = "新增")
    @PostMapping
    public LMResult<Boolean> add(@RequestBody AddCouponDTO addCouponDTO){
        Boolean result = couponMircoService.add(addCouponDTO);
        return LMResult.success(result);
    }

    @Operation(summary = "启用/禁用优惠券")
    @PutMapping("/upd_available/{id}")
    public LMResult<Boolean> updAvailable(@PathVariable Long id){
        Boolean result = couponMircoService.updAvailable(id);
        return LMResult.success(result);
    }

    @Operation(summary = "更新")
    @PutMapping
    public LMResult<Boolean> update(@RequestBody UpdateCouponDTO updateCouponDTO){
        Boolean result = couponMircoService.updateCoupon(updateCouponDTO);
        return LMResult.success(result);
    }

    @Operation(summary = "删除")
    @DeleteMapping("{id}")
    public LMResult<Boolean> remove(@PathVariable Long id){
        Boolean result = couponMircoService.removeCoupon(id);
        return LMResult.success(result);
    }


}
